package com.data.permission.rule.process;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @包名称 com.thrift.distributed.process
 * @类描述 <pre>应用启动完成后启动服务</pre>
 * @作者 zhangbo
 * @创建时间 2019/9/19
 * @版本 1.00
 * @修改记录 <pre>
 *     版本           修改人         修改日期         修改内容描述
 *     -----------------------------------------------------------
 *     1.00           Lenovo        2019/9/19
 *     -----------------------------------------------------------
 * </pre>
 */
@Component
@Order(value = 1)
public class ServiceRun implements CommandLineRunner {

    @Autowired
    private ZKRegistServer zkRegistServer;

    @Autowired
    private ProcessStart processStart;
    /*服务自检延迟时间*/
    @Value("${REGIST.CHECK.TIME:30}")
    private long CHECK_TIME;

    public static final ScheduledExecutorService SCHEDULED_EXECUTOR_SERVICE = new ScheduledThreadPoolExecutor(1);

    @Override
    public void run(String... strings) throws Exception {
        Thread serviceThread = new Thread(processStart);
        serviceThread.start();
        SCHEDULED_EXECUTOR_SERVICE.scheduleAtFixedRate(new RegistRunable(zkRegistServer),0,CHECK_TIME, TimeUnit.SECONDS);
    }
}
